<{include file="Public/top.html" }>
</head>
<body>
<div id="warpper">
    <div class="content">
        <div class="location">签到设置</div>
        <div class="ui-tab">
            <{include file="Sign/setNav.html"}>
        </div>

        <!--表格内容-->
            <div class="mainGrid">
                <table class="ui-table ui-body" style="width:500px;">
                    <thead>
                    <tr>
                        <th class="pct50" style="padding:0;"><span style="display:inline-block; width:50%; height:40px; line-height:40px; text-align:center; border-right:1px solid #e5e5e5;">连续签到天数</span><span style="display:inline-block; width:50%; text-align:center;">奖励积分</span></th>
                        <th class="pct20 last-col">操作</th>
                    </tr>
                    </thead>
                    <tbody id="tbl1">
                        <{foreach from=$data item=item}>
                            <tr>
                                <td>
                                    <input type="hidden" id="id" value="<{$item['id']|default:0}>">
                                    <input type="text" id="day" class="ui-text" style="width:45%; margin-right:10px;" value="<{$item['prizeRank']}>"  onkeyup="this.value=this.value.replace(/[^\d]/g,'') " onafterpaste="this.value=this.value.replace(/[^\d]/g,'') " />
                                    <input type="text" id="reward" class="ui-text" style="width:43%;" value="<{$item['extra']}>" onkeyup="this.value=this.value.replace(/[^\d]/g,'') " onafterpaste="this.value=this.value.replace(/[^\d]/g,'') " />
                                </td>
                                <td>
                                    <input type="button" class="del-button" value="清除" id="<{$item['id']}>" onclick="del(this)"/>
                                </td>
                            </tr>
                        <{/foreach}>
                        <tr>
                            <td colspan="2">
                                <input type="button" class="add-button" value="添加" onclick="addByScript()"/>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="integral_btn-group">
                <input type="submit" value="保存" id="btn" class="ui-button"/>
            </div>
    </div>
</div>
<{include file="Public/foot.html" }>
</body>
</html>
<script>
     var count = 0;
     function addByScript() {
         var table = document.getElementById("tbl1");
         var newRow = table.insertRow(table.rows.length-1);
         newRow.id = "row" + count;
         var contentCell = newRow.insertCell(-1);
         contentCell.innerHTML = '<input type="hidden" value="0">'+'<input type="text" class="ui-text" style="width:45%; margin-right:10px;">'+'<input type="text" class="ui-text" style="width:45%;" />';
         contentCell = newRow.insertCell(-1);
         var delBtn = document.createElement("input");
         delBtn.type = "button";
         delBtn.className = "button";
         delBtn.id = '';
         delBtn.className="del-button";
         delBtn.value = "删除";
         delBtn.onclick = new Function("del(this)");
         contentCell.appendChild(delBtn);
         count++;
        }

    function del(obj) {
        var row = obj.parentNode.parentNode;
        var id = obj.id;
        var url = "<{U('Sign/delContinuousLogin')}>";
        if(id==''){
            row.parentNode.removeChild(row);
            return true;
        } else{
            if(confirm("确认删除吗？")){
                $.getJSON(url,{id:id},function(data){
                    layer.msg(data.msg);
                    reloadPage();
                });
            } else return false;
        }
    }

    $('#btn').click(function(){
        var url = "<{U('Sign/saveContinuousLogin')}>";
        var arr = '';
        var i =0;
        var status = 0;
        $("#tbl1 td input[type='text'],input[type='hidden']").each(function(){
            if($(this).val()==''){
                $(this).css("border","2px solid #fe7f30");
                layer.msg('信息填写不完整');
                status = 1;
                return false;
            }else{
                $(this).css("border","1px solid #e5e5e5");
                i++;
                if(i%3==0){
                    arr += $(this).val()+';';
                } else arr += $(this).val()+',';
             }
        });
        if(status == 0 ){
            $.getJSON(url,{param:arr},function(data){
                layer.msg(data.msg);
                if(data.status == 0){
                    reloadPage();
                }
            });
        }

    });
    
    //1秒后刷新页面
    function reloadPage() {
        setTimeout(function () {
            location.reload();
        },1000);
    }

</script>